#define _CRT_SECURE_NO_WARNINGS 1
/*
http://ybt.ssoier.cn:8088/problem_show.php?pid=1254

*/

#include<iostream>
#include<queue>
using namespace std;
int n, m;
char pct[101][101] = { '\0' };
bool vis[101][101] = { false };
struct point {
	int x;
	int y;
	point(int _x = 0, int _y = 0) {
		x = _x; y = _y;
	}


};
point s, e;//start, end
point route[101][101] = { {0,0} };
int dx[] = { 0,0,1,-1 }, dy[] = { 1,-1,0,0 };

void bfs() {
	queue<point>q;
	q.push(s);
	vis[s.x][s.y] = true;
	route[s.x][s.y] = { -1,-1 };

	while (q.size()) {
		for (int i = 0; i < 4; i++) {
			int nx = q.front().x + dx[i],
				ny = q.front().y + dy[i];
			if (nx < 0 || nx >= n)
				continue;
			if (ny < 0 || ny >= m)
				continue;
			if (vis[nx][ny])
				continue;
			if (pct[nx][ny] == '#')
				continue;
			vis[nx][ny] = true;
			route[nx][ny] = q.front();
			if (e.x == nx && e.y == ny) {
				return;
			}
			q.push({ nx,ny });
		}
		q.pop();
	}
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> pct[i][j];
			if (pct[i][j] == 'S')
				s = { i,j };
			if (pct[i][j] == 'T')
				e = { i,j };
		}
	}
	bfs();
	int step = 0;
	int fx = e.x, fy = e.y;
	while (fx != -1 && fy != -1) {
		int tx = fx, ty = fy;
		fx = route[tx][ty].x;
		fy = route[tx][ty].y;
		cout << tx << ' ' << ty << "->" << fx << ' ' << fy << endl;
		if (fx != -1 && fy != -1)
			step++;
	}
	cout << step;

	return 0;
}
